def _src_compile_impl(ctx):
    outputs = []

    # g++ srouce1 source2 -o xxx.o -c
    for src in ctx.files.srcs:  # src: File
        out = ctx.actions.declare_file("{}.o".format(src.path[:-4]))
        print(">>> Compling {} -> {}".format(src, out))
        
        inputs = [src]
        inputs.extend(ctx.files.hdrs)

        args = ctx.actions.args()
        args.add(src)
        args.add("-o")
        args.add(out)
        args.add("-c")

        ctx.actions.run(
            executable = "/usr/bin/g++",
            arguments  = [args],
            inputs     = inputs,
            outputs    = [out],
        )
        outputs.append(out)

    return [DefaultInfo(files = depset(outputs))]


compile = rule (
    implementation = _src_compile_impl,
    attrs = {
        "srcs" : attr.label_list(
            allow_files = True,
            doc = "input source files",
        ),
        "hdrs" : attr.label_list(
            allow_files = True,
            doc = "input header files",
        ),
    },
    executable = False,
    test       = False,
)